﻿using KZ.Utilities;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using KZ.Express.H.ENT;
using KZ.Express.H.Presenter;
using System.Globalization;

namespace KZ.Express.H.Settings.PriceList
{
    public partial class OriginalPriceListView : BaseView
    {
        #region Private Variables

        #endregion

        #region Private Methods

        private void OriginalPriceListView_Load(object sender, EventArgs e)
        {
            LoadCarrier();
        }


        private void LoadCarrier()
        {
            try
            {
                cmbCarrierID.ValueMember = "CarrierID";
                cmbCarrierID.DisplayMember = "CarrierName";
                DataTable dt = _presenter.LoadDataTable<CarrierENT>(null);
                DataRow dr = dt.NewRow();
                dr["CarrierName"] = "--- Tất cả ---";
                dr["CarrierID"] = 0;
                dt.Rows.InsertAt(dr, 0);
                cmbCarrierID.DataSource = dt;
                cmbCarrierID.SelectedIndex = 0;
            }
            catch (BusinessLogicException ex)
            {
                ShowMessageBoxError(ex.Message);
            }
        }

        #endregion

        #region Constructors

        public OriginalPriceListView()
        {
            InitializeComponent();
            Initialize(dtgPriceList);

            _presenter = new BasePresenter(this);
            base.ObjectID = (int)Objects.OriginalPriceList;
            base.ActionName = "List";
            this.VisibleChanged += new EventHandler(View_VisibleChanged<PriceListENT>);
            this.dtgPriceList.Sorted += new EventHandler(Datagrid_Sorted);

            this.OnDeleteClick += new DeleteClickHandler(View_OnDeleteClick<PriceListENT>);
            this.btnSearch.Click += new EventHandler(View_OnSearchClick<PriceListENT>);
            this.btnViewAll.Click += new EventHandler(View_OnViewAllClick<PriceListENT>);

            colEffectedDate.DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
            colExpiredDate.DefaultCellStyle.Format = CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern;
            Global.SetDoubleBuffered(dtgPriceList);
        }

        #endregion

        #region Public Properties

        [Search]
        public int IsOriginal
        {
            get { return 1; }
        }

        [Search]
        public string PriceListCode
        {
            get { return txtPriceListCode.Text; }
            set { txtPriceListCode.Text = value; }
        }

        [Search]
        public string PriceListName
        {
            get { return txtPriceListName.Text; }
            set { txtPriceListName.Text = value; }
        }

        [Search]
        public string SupplierName
        {
            get { return txtSupplierName.Text; }
            set { txtSupplierName.Text = value; }
        }

        [Search]
        public int CarrierID
        {
            get { return Utility.IntParse(cmbCarrierID.SelectedValue); }
            set { cmbCarrierID.SelectedValue = value; }
        }

        public DataTable Carriers
        {
            set { cmbCarrierID.DataSource = value; }
        }

        #endregion
    }
}
